﻿using Ducu.BLL.NHMap;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Dialect;

namespace BuildDatabase
{
    class NHProvider
    {
        private static ISession _session;
        internal static ISession session
        {
            get
            {
                if (_session == null)
                {
                    _session = getConfig()
                        .BuildSessionFactory().OpenSession();
                }
                return _session;
            }
        }

        internal static FluentConfiguration getConfig()
        {
            string connStr = "server=localhost;Uid=root;database=ducu_dev;Charset=utf8";
            return Fluently.Configure()
                .Database(
                    MySQLConfiguration.Standard.ConnectionString(connStr).Dialect<MySQL5Dialect>()
                    .ShowSql().FormatSql())
                .Mappings(ConfigurationProvider.Action);
        }
    }
}
